<html>
<head><meta charset="utf-8"><title>Clippy started ICEing in rustc_infer/../canonicalize · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html">Clippy started ICEing in rustc_infer/../canonicalize</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212909303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212909303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212909303">(Oct 10 2020 at 10:20)</a>:</h4>
<p>Clippy got 2 really similar ICE reports recently, that don't seem to be caused by changes in Clippy:</p>
<ol>
<li><a href="https://github.com/rust-lang/rust-clippy/issues/6139">clippy#6139</a> (when calling <code>is_sized</code> on a <code>ty::Ty</code> produced by <code>hir_ty_to_ty</code>)</li>
<li><a href="https://github.com/rust-lang/rust-clippy/issues/6153">clippy#6153</a> (when calling <code>is_freeze</code> on a <code>ty::Ty</code> produced by <code>.pat_ty</code> or from a <code>FnSig</code>)</li>
</ol>
<p>The backtraces both go into <code>rustc_infer/../canonical</code> through multiple <code>TypeFoldable::fold_with</code> and similar. And the ICE occurs with <code>ReLateBound</code> when the <code>DebruijnIndex</code> is too big. </p>
<ol>
<li>ICEd here: <a href="https://github.com/rust-lang/rust/blob/5ddef544fa26c5535376fa424baf30cb985f7cb1/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs#L308-L314">https://github.com/rust-lang/rust/blob/5ddef544fa26c5535376fa424baf30cb985f7cb1/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs#L308-L314</a></li>
<li>ICEd here: <a href="https://github.com/rust-lang/rust/blob/5ddef544fa26c5535376fa424baf30cb985f7cb1/compiler/rustc_infer/src/infer/canonical/substitute.rs#L75">https://github.com/rust-lang/rust/blob/5ddef544fa26c5535376fa424baf30cb985f7cb1/compiler/rustc_infer/src/infer/canonical/substitute.rs#L75</a> (The indexing)</li>
</ol>
<p>The issue with 1. occurred on a trait object with a lifetime (<code>(dyn T&lt;'_&gt;)</code>), which <code>ty::TyKind</code> was <code>ty::Dynamic(.., ReStatic)</code>. Removing the LT prevented the ICE</p>
<p>For 2. I didn't go as deep in the debugging, but when printing the debug info of the <code>ty::Ty</code> I get:</p>
<div class="codehilite"><pre><span></span><code>[clippy_lints/src/mut_key.rs:124] ty.kind() = Adt(
    params::types::Base,
    [
        ReLateBound(DebruijnIndex(0), BrAnon(2)),
    ],
)
[clippy_lints/src/mut_key.rs:125] ty = params::types::Base&lt;&#39;_&gt;
</code></pre></div>


<p>So it seems to be a similar issue.</p>
<p>Are there any preconditions that Clippy has to check before calling <code>ty::Ty::is_sized</code> or <code>ty::Ty::is_freeze</code>?</p>



<a name="212909655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212909655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212909655">(Oct 10 2020 at 10:31)</a>:</h4>
<p>Are regions getting erased before invoking those queries?</p>



<a name="212909772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212909772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212909772">(Oct 10 2020 at 10:34)</a>:</h4>
<p>rustc_middle::ty::TyCtxt - Rust - <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.erase_late_bound_regions">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.erase_late_bound_regions</a></p>



<a name="212909775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212909775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212909775">(Oct 10 2020 at 10:34)</a>:</h4>
<p>That function should at least fix the first ICE</p>



<a name="212909843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212909843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212909843">(Oct 10 2020 at 10:36)</a>:</h4>
<p>The second one may require just <code>erase_regions</code></p>



<a name="212910726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212910726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212910726">(Oct 10 2020 at 10:59)</a>:</h4>
<p>I don't think that <code>erase_later_bound_regions</code> is correct here because it only erases regions bound at exactly the level of the binder. Clippy should probably skip calling those methods if <code>ty.has_escaping_bound_vars()</code>. <code>ty.needs_infer()</code> and <code>ty.has_placeholders()</code> should also be false before calling them, but if either of those is true you should have an <code>InferCtxt</code>and can call <code>type_known_to_meet_bound_modulo_regions</code> instead.</p>



<a name="212911628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212911628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212911628">(Oct 10 2020 at 11:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116118">Matthew Jasper</span> <a href="#narrow/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize/near/212910726">said</a>:</p>
<blockquote>
<p>but if either of those is true you should have an <code>InferCtxt</code>and can call <code>type_known_to_meet_bound_modulo_regions</code> instead.</p>
</blockquote>
<p>Both <code>is_sized</code> and <code>is_freeze</code> call this function under the hood. And this then panics later. I'll try checking <code>ty.has_escaping_bound_vars()</code> before the calls though.</p>
<p>I'll also try the <code>erase_*regions</code> functions, but if they only remove the first layer of bounds, I don't have much hope.</p>



<a name="212912322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212912322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212912322">(Oct 10 2020 at 11:45)</a>:</h4>
<p><code>is_sized</code> and <code>is_freeze</code> first go through the query cache though, which shouldn't contain inference variables or placeholders.</p>



<a name="212912929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Clippy%20started%20ICEing%20in%20rustc_infer/../canonicalize/near/212912929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Clippy.20started.20ICEing.20in.20rustc_infer.2F.2E.2E.2Fcanonicalize.html#212912929">(Oct 10 2020 at 12:03)</a>:</h4>
<p>Alright, placing <code>ty.has_escaping_bound_vars()</code> in front of those calls fixed the ICEs. My question now is: How do we know if we have to place this before those queries? Should we just check that every time we call one of those queries? Only if an ICE occurs? ...?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>